﻿@model WebEntities.Models.ProductInfo.Product

@{
    ViewBag.Title = "网站管理平台_编辑产品";
}

@section HeadContent
{
    <link href="/Content/data-view.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var getProductContent = function () {
            var content = App.Description.getValue();
            if (App.ProductContent.iframe != null) {
                content = App.ProductContent.iframe.dom.contentWindow.getContent();
            }
            App.Description.setValue(content);
        }

        var onDeleteImgSuccess = function (response, data) {
            Ext.Msg.show({ title: '提示', msg: data.result.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.INFO, modal: true,
                fn: function (btn) {
                    var imgview = App.ImageView;
                    imgview.store.reload();
                }
            });
        };

        var onDeleteImgFailure = function (response, data) {
            Ext.Msg.show({ title: '提示', msg: data.result.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR, modal: true });
        };
    </script>
}

@(Html.X().Viewport()
    .Layout("fit")
    .Items(
        Html.X().TabPanel().Items(
            Html.X().FormPanel()
                .ID("FormPanel1")
                .Layout("Column")
                .Title("产品信息")
                .Items(
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Padding(5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                            Html.X().HiddenFor(m => m.ProductID).ID("ProductID"),
                            Html.X().HiddenFor(m => m.Description).ID("Description"),
                            Html.X().TextFieldFor(m => m.ProductName).ID("ProductName").FieldLabel("产品名称").AllowBlank(false).MaxLength(50),
                            Html.X().ComboBoxFor(m => m.ProdCataID).ID("ProdCataID").FieldLabel("所属产品目录").Editable(false)
                                .Store(Html.X().Store()
                                    .Model(Html.X().Model().IDProperty("ProdCataID")
                                        .Fields(
                                            new ModelField("ProdCataID", ModelFieldType.Int),
                                            new ModelField("ProdCataName")
                                        )
                                    )
                                    .Proxy(Html.X().AjaxProxy().Url(Url.Action("GetAllProductCata", "ProductCata")).Reader(Html.X().JsonReader().Root("data")))
                                )
                                .DisplayField("ProdCataName")
                                .ValueField("ProdCataID"),
                            Html.X().TextFieldFor(m => m.Company).ID("Company").FieldLabel("生产商").MaxLength(50),
                            Html.X().TextFieldFor(m => m.Address).ID("Address").FieldLabel("生产商地址").MaxLength(200),
                            Html.X().TextFieldFor(m => m.Keywords).ID("Keywords").FieldLabel("关键字").MaxLength(200),
                            Html.X().HiddenFor(m => m.ProductCover).ID("ProductCover"),
                            Html.X().FileUploadField().ID("ProductCoverFile").FieldLabel("产品封面图").Icon(Icon.ImageAdd).ButtonText("").Text(Model.ProductCover)
                        ),
                    Html.X().Panel()
                        .Border(false)
                        .ColumnWidth(0.5)
                        .Padding(5)
                        .Layout("form")
                        .Defaults(
                            Html.X().Parameter().Name("AnchorHorizontal").Value("90%")
                        )
                        .Items(
                            Html.X().TextFieldFor(m => m.ProductType).ID("ProductType").FieldLabel("产品类别").MaxLength(50),
                            Html.X().TextFieldFor(m => m.UnitPrice).ID("UnitPrice").FieldLabel("价格").MaxLength(50),
                            Html.X().TextFieldFor(m => m.Brand).ID("Brand").FieldLabel("品牌"),
                            Html.X().TextFieldFor(m => m.AppDomain).ID("AppDomain").FieldLabel("应用领域"),
                            Html.X().NumberFieldFor(m => m.SortNum).ID("SortNum").FieldLabel("排序序号").MinValue(0),
                            Html.X().ComboBoxFor(m => m.IsShow).ID("IsShow").FieldLabel("是否显示").Editable(false)
                                .Items(
                                    Html.X().ListItem().Text("隐藏").Value("0").Mode(ParameterMode.Raw),
                                    Html.X().ListItem().Text("显示").Value("1").Mode(ParameterMode.Raw)
                                )
                        )
                )
                .TopBar(
                    Html.X().Toolbar().Items(
                        Html.X().Button().Text("保存").Icon(Icon.Disk)
                            .DirectEvents(de =>
                            {
                                de.Click.Action = "EditProduct";
                                de.Click.EventMask.ShowMask = true;
                                de.Click.EventMask.Msg = "正在保存";
                                de.Click.Success = "ext.net.comjs.onSubmitSuccess";
                                de.Click.Failure = "ext.net.comjs.onSubmitFailure";
                                de.Click.IsUpload = true;
                            })
                            .Listeners(ls =>
                            {
                                ls.Click.Handler = "getProductContent(); return ext.net.comjs.onFormSubmit()";
                            })
                    )
                )
                .BottomBar(Html.X().StatusBar().DefaultText("Ready"))
                        .Listeners(ls => ls.ValidityChange.Handler = "ext.net.comjs.setFormStatusBar(this, valid)"),
            Html.X().Panel().ID("ProductContent").Title("产品描述").Loader(
                Html.X().ComponentLoader()
                    .Url(Url.Action("ProductDescription"))
                    .Params(p =>
                    {
                        p.Add(new Parameter("prodId", Model.ProductID.ToString()));
                    })
                    .Mode(LoadMode.Frame)
                    .LoadMask(lm =>
                    {
                        lm.ShowMask = true;
                        lm.Msg = "加载中，请稍候...";
                    })
            ),
            Html.X().Panel().ID("ProductImg").Title("产品图片")
                .Cls("images-view")
                .Layout("fit")
                .Flex(1)
                .Items(
                    Html.X().DataView().ID("ImageView")
                        .Store(
                            Html.X().Store()
                                //.DataSource(ViewData["ProductImgList"])
                                .Proxy(
                                    Html.X().AjaxProxy().Url(Url.Action("GetAllProductImg", "ProductImg"))
                                        .API(api => api.Destroy = Url.Action("DeleteProductImg", "ProductImg"))
                                        .Reader(Html.X().JsonReader().Root("data"))
                                )
                                .Model(Html.X().Model().Fields(
                                    Html.X().ModelField().Name("ID"),
                                    Html.X().ModelField().Name("ProductID"),
                                    Html.X().ModelField().Name("Title"),
                                    Html.X().ModelField().Name("ImgUrl"),
                                    Html.X().ModelField().Name("SortNum"),
                                    Html.X().ModelField().Name("Description"))
                                )
                                .AutoLoadParams(ap => ap.Add(new Parameter("prodId", Model.ProductID.ToString())))
                        )
                        .OverItemCls("x-item-over")
                        .TrackOver(true)
                        .ItemSelector("div.thumb-wrap")
                        .EmptyText("没有产品图片")
                        .MultiSelect(true)
                        .Tpl(
                            Html.X().XTemplate().Html(
                                @<text>
                                    <tpl for=".">
								        <div class="thumb-wrap" id="pimg_{ID}">
									        <div class="thumb"><img src="{ImgUrl}" alt="{Title}" title="{Description}" /></div>
									        <span class="x-editable">{Title}</span>
								        </div>
							        </tpl>
							        <div class="x-clear"></div>
                                </text>
                            )
                        )
                        .AutoScroll(true)
                )
                .TopBar(
                    Html.X().Toolbar()
                        .Items(
                            Html.X().Button().Text("上传图片").Icon(Icon.ImageAdd)
                                .DirectClickAction("NewProductImgWindow", "ProductImg", new { prodId = Model.ProductID }),
                            Html.X().Button().ID("BtnDeleteSel").Text("删除图片").Icon(Icon.ImageDelete)
                                .DirectEvents(de =>
                                {
                                    de.Click.Url = Url.Action("DeleteProductImg", "ProductImg");
                                    de.Click.ExtraParams.Add(new Parameter("images", "App.ImageView.getRowsValues({ selectedOnly : true })", ParameterMode.Raw));
                                    de.Click.Confirmation.ConfirmRequest = true;
                                    de.Click.Confirmation.Title = "提示";
                                    de.Click.Confirmation.Message = "是否要删除选中的产品图片？";
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.EventMask.Msg = "正在保存";
                                    de.Click.Success = "onDeleteImgSuccess";
                                    de.Click.Failure = "onDeleteImgFailure";
                                }),
                            Html.X().Button().Text("刷新视图").Icon(Icon.ArrowRefresh)
                                .Listeners(ls =>
                                {
                                    ls.Click.Handler = "App.ImageView.getStore().reload();";
                                })
                        )
                )
        )
    )
    )

